<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Add extends CI_Controller {
function __construct()
    {
        parent::__construct();
    	$this->load->library('session');
		$this->load->helper('url');
    	$this->load->database();
    	$this->load->model("centermod");
    	
	}


	
//################### section load page##################
/*
 * add new tour
 * 
 * */	
	function Addtour()
			{
			//$this->session->unset_userdata('user');
		if($this->session->userdata("user")==false)
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
					$this->load->view("tour");				
							
										
			}
			
			}//function page tour
	


/*
 * add new bus
 * 
 * */	
	function Addbus()
			{
			//$this->session->unset_userdata('user');
		if($this->session->userdata("user")==false)
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
					
				$fk_idtours=$this->input->get_post("fk_idtours"); 
				if($fk_idtours!=''){
				$data=array("fk_idtours"=>$fk_idtours);
				//print_r($data);
				$this->load->view("bus",$data);				
				}else{ header('Location:index.php?liste/listtour');}			
										
			}
			
			}//function page bus
				
// add a new incritpion

	function addbooking($idbus=0,$idtour=0)
			{
			//$this->session->unset_userdata('user');
		if($this->session->userdata("user")==false)
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{

				$ck_bus_in_tour=$this->centermod->istoursbus($idbus,$idtour);
				if($ck_bus_in_tour)
				{
				//$fk_idtours=$this->input->get_post("fk_idtours"); 
				//$data=array("fk_idtours"=>$fk_idtours);
				//print_r($data);
				$infotour=$this->centermod->ltourbyid($idtour);
				$forfaits=$this->centermod->lforfaitbyid($idtour);
				$addbookingID=rand();
				$this->session->set_userdata(array("addbookingID"=>$addbookingID));
				$description=$infotour[0]["description"];
				$fixedprice=$infotour[0]["fixedprice"];
				
					$data=array("idbus"=>$idbus,"idtour"=>$idtour,"desc"=>$description,"addbookingID"=>$addbookingID,"fixedprice"=>$fixedprice,"forfait"=>$forfaits,"infotour"=>$infotour);
					$this->load->view("inscription",$data);				
					
				}else 
				{
					header('Location:index.php?liste/listtour');
				
				}// if 	$ck_bus_in_tour 		
										
			}//if session user
			
			}//function page bus

			
/*add booking by gourp*/

	function addgroup($idbus=0,$idtour=0)
			{
			//$this->session->unset_userdata('user');
		if($this->session->userdata("user")==false)
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
				$addbookingID=rand();
				$this->session->set_userdata(array("addbookingID"=>$addbookingID));
				$ck_bus_in_tour=$this->centermod->istoursbus($idbus,$idtour);
				if($ck_bus_in_tour)
				{
				//$fk_idtours=$this->input->get_post("fk_idtours"); 
				//$data=array("fk_idtours"=>$fk_idtours);
				//print_r($data);
					$infotour=$this->centermod->ltourbyid($idtour);
					$description=$infotour[0]["description"];
					$fixedprice=$infotour[0]["fixedprice"];
					$data=array("idbus"=>$idbus,"idtour"=>$idtour,"addbookingID"=>$addbookingID,"desc"=>$description,"fixedprice"=>$fixedprice)	;
					$this->load->view("inscrgroup",$data);				
					
				}else 
				{
					header('Location:index.php?liste/listtour');
				
				}// if 	$ck_bus_in_tour 		
										
			}//if session user
			
			}//function page bus

			
			
			
			
/*liste seach client by telphonte	*/
		function seachclientbytel($tel="000-000000")
			{
				$lclientexit=$this->centermod->seachclientbytel(trim($tel));
				
				if(count($lclientexit)==1)
				{
					$lclientexit["etat"]="yes";
									
				}else{
				   
				 	$lclientexit["etat"]="no";
				 	
				 }
				 echo json_encode($lclientexit );
				}	
			

				
				
				
				
				
				
			
function actionAdd($type)
			{
			//$this->session->unset_userdata('user');
		if($this->session->userdata("user")==false)
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{

				switch ($type)
				{
				 case "tour":
      						  $TourName=$this->input->get_post("TourName"); 
      						  $TourCode=$this->input->get_post("TourCode"); 
      						  $Date=$this->input->get_post("Date"); 
      						  $time=$this->input->get_post("time"); 
      						  $lieu=$this->input->get_post("lieu"); 
      						  $Description=$this->input->get_post("Description"); 
      						  //$fixedprice=$this->input->get_post("fixedprice");
      						  $forfaittype=$this->input->get_post("chambreyesno"); 
      						  
      						  $data=array( "name"=>$TourName,
      						  			   "code"=>$TourCode,
      						  			   "Date"=>$Date,
										   "Description"=>$Description,
      						  			   "forfaittype"=>$forfaittype,
      						  				"time"=>$time,
      						  				"lieu"=>$lieu
      						  				);
							
      			//ici pour switch the forfait type 
      			//if egale 0  forfait o chambre
      			//if egale 1 forfait 1234(s.d.t.q)			  				
      				if($TourName!=""&&$TourCode!=""&&$Date=!""&&$Description!=""&&$forfaittype!="")
      				 {
      						 if($forfaittype==0)
								{
									
									$chambretype=0;
									$title=$this->input->get_post("c0ttle"); 
									$priceadult=$this->input->get_post("c0adult"); 
									$pricechild=$this->input->get_post("c0child"); 
									$idinsert=$this->centermod-> insertetemplate("tours",$data);
									$data2=array("title"=>$title,"chambretype"=>$chambretype,"priceadult"=>$priceadult,"pricechild"=>$pricechild,"fk_idtours"=>$idinsert);
									$idinsert_f=$this->centermod-> insertetemplate("forfaits",$data2);
									for($i=1;$i<5;$i++)
									{
										$chambretype=$i;
										$title=""; 
										$priceadult=0; 
										$pricechild=0; 
										$data_ch=array("title"=>$title,"chambretype"=>$chambretype,"priceadult"=>$priceadult,"pricechild"=>$pricechild,"fk_idtours"=>$idinsert);
										$idinsert_f=$this->centermod-> insertetemplate("forfaits",$data_ch);
										
									}
								}
							if($forfaittype==1)
								{
									$idinsert=$this->centermod-> insertetemplate("tours",$data);
									for($i=0;$i<5;$i++)
									{
									$chambretype=$i;
									
									 if($i==0)
									 	{
										$title=""; 
										$priceadult=0; 
										$pricechild=0; 
										$data_ch=array("title"=>$title,"chambretype"=>$chambretype,"priceadult"=>$priceadult,"pricechild"=>$pricechild,"fk_idtours"=>$idinsert);
										$idinsert_f=$this->centermod-> insertetemplate("forfaits",$data_ch);
									   }
									$title=$this->input->get_post("c".$i."ttle"); 
									$priceadult=$this->input->get_post("c".$i."adult"); 
									$pricechild=$this->input->get_post("c".$i."child"); 
									$data_ch=array("title"=>$title,"chambretype"=>$chambretype,"priceadult"=>$priceadult,"pricechild"=>$pricechild,"fk_idtours"=>$idinsert);
									$idinsert_f=$this->centermod-> insertetemplate("forfaits",$data_ch);
									}
								
								}							
      						  				
								$data=array("message"=>"The tour is Added");
      						 	$this->load->view("tour",$data);
      						 
      				  } else 
      				   {
      				   	header('Location:index.php?add/addtour');
      				  }	
      			 	break;
				
				
				 case "bus":
      						  $codebus=$this->input->get_post("codebus"); 
      						  $seatquantity=$this->input->get_post("seatquantity"); 
      						  $Guider=$this->input->get_post("Guider"); 
      						  $Driver=$this->input->get_post("Driver"); 
      						  $Bus_Company=$this->input->get_post("BusCompany"); 
      						  $hotelinfo=$this->input->get_post("HotelInfo"); 
      						  $fk_idtours=$this->input->get_post("fk_idtours");
      						  $seatavaible=$seatquantity;
      						  
      						   
      						  $data=array( "code"=>$codebus,
      						  			   "seatqty"=>$seatquantity,
      						  				"seatavaible"=>$seatavaible,
      						  			   "Driver"=>$Driver,
      						  			   "Guider"=>$Guider,
										   "Bus_Company"=>$Bus_Company,
      									   "hotel_info"=>$hotelinfo,
      						               "fk_idtours"=>$fk_idtours
      						  );
      						  if($codebus!=""&$seatquantity!=""&&$hotelinfo=!"")
      						  {
      						 	$idinsert=$this->centermod-> insertetemplate("bus",$data);
								$data=array("message"=>"The Bus is Added","fk_idtours"=>$fk_idtours);
      						 	//print_r($idinsert);
								$this->load->view("bus",$data);
      						  } else 
      						  {
      						  	header('Location:index.php?liste/listtour');
      						  	
      						  }	
      						 	break;
      						 	
      						 	
      			 case "booking":
      			 			    			 	
      						  $addbookingID=$this->input->get_post("addbookingID");
      			 			  $idclient=$this->input->get_post("idclient");
      						  $Telephone=$this->input->get_post("Telephone");  
      						  $FirstName=$this->input->get_post("FirstName"); 
      						  $LastName=$this->input->get_post("LastName");
      						  $Email=$this->input->get_post("Email"); 
      						  $unitprice=$this->input->get_post("unitprice"); 
      						  $Language=$this->input->get_post("Language");
      						  $address=$this->input->get_post("address");
      						  $orginalprice=$this->input->get_post("orginalprice");
      						    						 
      						  if($Telephone!="" && $addbookingID==$this->session->userdata("addbookingID"))
      						  {
      						  
      						  	
      						  $fk_idclient=0;
      						  if($idclient<=0)
      						  {
      						  	$data=array("firstname"=>$FirstName,"lastname"=>$LastName,"telphone"=>$Telephone,"email"=>$Email,"language"=>$Language,"address"=>$address);
      						  	$idinsert=$this->centermod-> insertetemplate("clients",$data);
      						  	$fk_idclient=$idinsert;
      						  	
      						  	      						  	
      						  }else 
      						  	{
      						  		$lclientbyid=$this->centermod->seachclientbyid($idclient);
      						  		
      						  		$data=array();
      						  		if($lclientbyid[0]["firstname"]!=$FirstName)
      						  		{
      						  			$data["firstname"]=$FirstName;
      						  		
      						  		}
      						  		
      						  		if($lclientbyid[0]["lastname"]!=$LastName)
      						  		{
      						  			$data["lastname"]=$LastName;
      						  		
      						  		} 
      						  	
      						  		if($lclientbyid[0]["email"]!=$Email)
      						  		{
      						  			$data["email"]=$Email;
      						  		
      						  		}	
      						  
      						  		if($lclientbyid[0]["language"]!=$Language)
      						  		{
      						  			$data["language"]=$Language;
      						  		
      						  		}
      						  		if($lclientbyid[0]["address"]!=$address)
      						  		{
      						  			$data["address"]=$address;
      						  		
      						  		}
      						  		
      						  		if(empty($data)!=true){
      						  		$this->centermod->updatetemplate("clients",$data,"idclients=$idclient");
      						  		}
      						  	$fk_idclient=$idclient;
      						  	}
      						  	$numberpeople=$this->input->get_post("numberpeople"); 
      						  	$SalsePrice=$this->input->get_post("SalsePrice"); 
      						  	$nbchild=$this->input->get_post("nbchild"); 
      						  	$Chambre=$this->input->get_post("Chambre"); 
      						  	$Reminder=$this->input->get_post("Reminder"); 
      						  	$Paid=$this->input->get_post("Paid"); 
      						  	$idbus=$this->input->get_post("idbus");
      						  	$data1=array("salesprice"=>$SalsePrice,"numberpeople"=>$numberpeople,"nbchild"=>$nbchild,"chambre"=>$Chambre,"reminder"=>$Reminder,"orginalprice"=>$orginalprice,"chambreqty"=>1,"paid"=>$Paid,"fk_idbus"=>$idbus,"fk_idclients"=>$fk_idclient);
      						  	$idinsert1=$this->centermod-> insertetemplate("inscriptions",$data1);
      						  	if($idinsert1>0)
      						  	{
      						  		//print_r("$idinsert1");
      						  		$this->centermod->sustactionper($idbus);
      						  		$linfoper=$this->centermod->seachclientbyid($fk_idclient);
      						  		$dataconfirm["infoper"]=$linfoper[0];
      						  		$dataconfirm["infoinscr"]=$data1;
      						  		$dataconfirm["idinscr"]=$idinsert1;
      						  		$dataconfirm["iduser"]=$this->session->userdata("idusers");
      						  		$dataconfirm["orginalprice"]=$orginalprice;
      						  		$idcomfirm=rand();
      						  		$this->session->set_userdata(array("idcomfirm"=>$idcomfirm));
      						  		$dataconfirm["idcomfirm"]=$idcomfirm;
      						  		$this->load->view("confirm",$dataconfirm);
      						  	}
      						  		$this->session->set_userdata(array("addbookingID"=>""));
      						  	}else 
      						  	{
      						  		//header('Location:index.php?liste/listtour');
      						  		echo "<h2>fait deux fois action booking , l'erreur 101</h2><a href='index.php?liste/listtour'>back to menu</a>";
      						  	}
      						  	
      						  	break;
      			
				 case "bookinggroup":
      			 			   $addbookingID=$this->input->get_post("addbookingID");  			 	
      						  $idclient=$this->input->get_post("idclient");
      						  $Telephone=$this->input->get_post("Telephone");  
      						  $FirstName=$this->input->get_post("FirstName"); 
      						  $LastName=$this->input->get_post("LastName");
      						  $Email=$this->input->get_post("Email"); 
      						  $Language=$this->input->get_post("Language");
      						  $address=$this->input->get_post("address");
      						  $unitprice=$this->input->get_post("unitprice"); 						 
      						  if($Telephone!="" &&  $addbookingID==$this->session->userdata("addbookingID"))
      						  {
      						  
      						  	
      						  $fk_idclient=0;
      						  if($idclient<=0)
      						  {
      						  	$data=array("firstname"=>$FirstName,"lastname"=>$LastName,"telphone"=>$Telephone,"email"=>$Email,"language"=>$Language,"address"=>$address);
      						  	$idinsert=$this->centermod-> insertetemplate("clients",$data);
      						  	$fk_idclient=$idinsert;
      						  	      						  	
      						  }else 
      						  	{
      						  		$lclientbyid=$this->centermod->seachclientbyid($idclient);
      						  		$flagchange=0;
      						  		
      						  		if($lclientbyid[0]["firstname"]!=$FirstName)
      						  		{
      						  			$data["firstname"]=$FirstName;
      						  			$flagchange=1;
      						  		}
      						  		
      						  		if($lclientbyid[0]["lastname"]!=$LastName)
      						  		{
      						  			$data["lastname"]=$LastName;
      						  			$flagchange=1;
      						  		} 
      						  	
      						  		if($lclientbyid[0]["email"]!=$Email)
      						  		{
      						  			$data["email"]=$Email;
      						  			$flagchange=1;
      						  		}	
      						  
      						  		if($lclientbyid[0]["language"]!=$Language)
      						  		{
      						  			$data["language"]=$Language;
      						  			$flagchange=1;
      						  		}
      						  	    
      						  		
      						  		if($lclientbyid[0]["address"]!=$address)
      						  		{
      						  			$data["address"]=$address;
      						  			$flagchange=1;
      						  		}
      				//if we have somme change we will update BaseDonne		  		
      						  		if($flagchange==1)
      						  		{
      						  		$this->centermod->updatetemplate("clients",$data,"idclients=$idclient");
      						  		}
      						  	$fk_idclient=$idclient;
      						  	}
      						  	$numberpeople=$this->input->get_post("numberpeople"); 
      						  	$SalsePrice=$this->input->get_post("SalsePrice"); 
      						  	$Chambre=$this->input->get_post("Chambre"); 
      						  	$Reminder=$this->input->get_post("Reminder"); 
      						  	$Paid=$this->input->get_post("Paid"); 
      						  	$idbus=$this->input->get_post("idbus");
      						  	$chambr1=$this->input->get_post("c1");
      						  	$chambr2=$this->input->get_post("c2");
      						  	$chambr3=$this->input->get_post("c3");
      						  	$chambr4=$this->input->get_post("c4");
      						  	$group=1;
      						  	$idinsert_c1=0;
      						  	$idinsert_c2=0;
      						  	$idinsert_c3=0;
      						  	$idinsert_c4=0;
      						  	if($chambr1>0)
      						  	{
      						  		$data_c1=array("salesprice"=>$SalsePrice,"numberpeople"=>$numberpeople,"chambre"=>"1","chambreqty"=>$chambr1,"reminder"=>$Reminder,"group"=>$group,"paid"=>$Paid,"fk_idbus"=>$idbus,"fk_idclients"=>$fk_idclient);
      						  		$idinsert_c1=$this->centermod-> insertetemplate("inscriptions",$data_c1);
      						  	}
      						  	
      						  	if($chambr2>0)
      						  	{
      						  		$data_c2=array("salesprice"=>$SalsePrice,"numberpeople"=>$numberpeople,"chambre"=>"2","chambreqty"=>$chambr2,"reminder"=>$Reminder,"group"=>$group,"paid"=>$Paid,"fk_idbus"=>$idbus,"fk_idclients"=>$fk_idclient);
      						  		$idinsert_c2=$this->centermod-> insertetemplate("inscriptions",$data_c2);
      						  	}
      						  
      						     if($chambr3>0)
      						  	{
      						  		$data_c3=array("salesprice"=>$SalsePrice,"numberpeople"=>$numberpeople,"chambre"=>"3","chambreqty"=>$chambr3,"reminder"=>$Reminder,"group"=>$group,"paid"=>$Paid,"fk_idbus"=>$idbus,"fk_idclients"=>$fk_idclient);
      						  		$idinsert_c3=$this->centermod-> insertetemplate("inscriptions",$data_c3);
      						  	}
      						  	
      						    if($chambr4>0)
      						  	{
      						  		$data_c4=array("salesprice"=>$SalsePrice,"numberpeople"=>$numberpeople,"chambre"=>"4","chambreqty"=>$chambr4,"reminder"=>$Reminder,"group"=>$group,"paid"=>$Paid,"fk_idbus"=>$idbus,"fk_idclients"=>$fk_idclient);
      						  		$idinsert_c4=$this->centermod-> insertetemplate("inscriptions",$data_c4);
      						  	}
      						  	$this->session->set_userdata(array("addbookingID"=>""));
      						  	if($idinsert_c1>0||$idinsert_c2>0||$idinsert_c3>0||$idinsert_c4>0)
      						  	{
      						  		
      						  		$this->centermod->sustactionper($idbus);
      						  		$linfoper=$this->centermod->seachclientbyid($fk_idclient);
      						  		$dataconfirm["infoper"]=$linfoper[0];
      						  		
      						  		$dataconfirm["infoinscr"]=$data_c1;
      						  		
      						  		if($idinsert_c1>0)
      						  		{$dataconfirm["mutlichambre"]["s"]=$chambr1;
      						  		 $dataconfirm["idinscr"][]=$idinsert_c1;	
      						  		}
      						  		else {$dataconfirm["mutlichambre"]["s"]=0;}
      						  		if($idinsert_c2>0)
      						  		{$dataconfirm["mutlichambre"]["d"]=$chambr2;
      						  		  $dataconfirm["idinscr"][]=$idinsert_c2;
      						  		}
      						  		else {$dataconfirm["mutlichambre"]["d"]=0;}
      						  		if($idinsert_c3>0)
      						  		{$dataconfirm["mutlichambre"]["t"]=$chambr3;
      						  		 $dataconfirm["idinscr"][]=$idinsert_c3;
      						  		}
      						  		else {$dataconfirm["mutlichambre"]["t"]=0;}
      						  		if($idinsert_c4>0)
      						  		{$dataconfirm["mutlichambre"]["q"]=$chambr4;
      						  		  $dataconfirm["idinscr"][]=$idinsert_c4;
      						  		}
      						  		else {$dataconfirm["mutlichambre"]["q"]=0;}
      						  		
      						  		$dataconfirm["unitprice"]=$unitprice;
      						  		$dataconfirm["iduser"]=$this->session->userdata("idusers");
      						  		$idcomfirm=rand();
      						  		$this->session->set_userdata(array("idcomfirm"=>$idcomfirm));
      						  		$dataconfirm["idcomfirm"]=$idcomfirm;
      						  		$this->load->view("confirmgroup",$dataconfirm);
      						  		
      						  		
      						  	}
      						  	
      						  	}else 
      						  	{
      						  		echo "<h2>fait deux fois action booking group, l'erreur 101</h2><a href='index.php?liste/listtour'>back to menu</a>";
      						  		//header('Location:index.php?liste/listtour');
      						  	}
      						  	
      						  	break;
      						  	
      				 case "invoice":
      				 			date_default_timezone_set('America/Montreal');
      				 			$idcomfirm=$this->input->get_post("idcomfirm");
      				 			$idinscr=$this->input->get_post("idinscr");
      						  	$iduser=$this->input->get_post("iduser");
      						  	$addionalprixcommentaire=$this->input->get_post("addionalprixcommentaire");
      						  	$prixadditonal=$this->input->get_post("prixadditonal");
      						  	$typepaiement=$this->input->get_post("typepaid");
      						  	$balance=$this->input->get_post("balance");
      						  	$idclients=$this->input->get_post("idcleint");
      						  
      						  	if($idinscr!=""&&$iduser!=""&&$idcomfirm==$this->session->userdata("idcomfirm"))
      						  	{
      						  		$data=array("addionalprixcommentaire"=>$addionalprixcommentaire,"prixadditonal"=>$prixadditonal,"typepaiement"=>$typepaiement,"balance"=>$balance,"createdtime"=>date('Y-m-d H:i:s'));
      						  		$idinsert=$this->centermod-> insertetemplate("invoice",$data);
      						  		$data2=array("insrc_idinscriptions"=>$idinscr,"inv_idinvoice"=>$idinsert,"users_idusers"=>$iduser);
      						  		$idinsert_relatif=$this->centermod-> insertetemplate("relatif_invoice",$data2);
      						  		$this->centermod->changeflag($idinscr);
      						  		$linfoper=$this->centermod->seachclientbyid($idclients);
      						  		$infoallforinvoice=$this->centermod->allinfoforinvoice($idinscr);
      						  		//print_r($idinscr);
      					  		/* convertir le chambrel type*/
      						  		
      						  		 switch($infoallforinvoice[0]['chambre']){
										case '1':
											$typechambre= 'Single X'.$infoallforinvoice[0]['chambreqty'];
										break;
										case '2':
											$typechambre= 'Double X'.$infoallforinvoice[0]['chambreqty'];
										break;
										case '3':
											$typechambre= 'Triple X'.$infoallforinvoice[0]['chambreqty'];
										break;
												case '4':
											$typechambre= 'Quadruple X'.$infoallforinvoice[0]['chambreqty'];
										break;
											}
											

								switch($infoallforinvoice[0]['paid'])
									{
								case '1':
									$paid= 'Yes';
									break;
								case '0':
									$paid='No';
									break;
									} 			
						  		/*___________________________*/
      						  		$page="code:".$infoallforinvoice[0]['tourname']."-".$infoallforinvoice[0]["tourcode"].";Date:".$infoallforinvoice[0]["tourdate"].";lastname:".$infoallforinvoice[0]['lastname'].";firstname:".$infoallforinvoice[0]['firstname']
      						  		.";telphone:".$linfoper[0]['telphone'].";email:".$linfoper[0]['email'].",address".$linfoper[0]['address'].";people:1".";chambre:".$typechambre.";salesprice:".$infoallforinvoice[0]['salesprice'].";balance:".$infoallforinvoice[0]['balance'].";Paid:".$paid.";typepaiement:".$infoallforinvoice[0]['typepaiement'].
      						  		";agency:". $infoallforinvoice[0]['agency'].";agent: ". $infoallforinvoice[0]['agent'].";language:".$infoallforinvoice[0]['language'].
      						  		";description:".$infoallforinvoice[0]['description'];
      $pagedata=array('page'=>$page);
      $updatepage=$this->centermod->updatetemplate("invoice",$pagedata,"idinvoice=$idinsert");	
	  $data_invoice["infoper"]=$linfoper;
      $data_invoice["allinfo"]=$infoallforinvoice;
      $data_invoice["idinvoice"]=$idinsert;
      $data_invoice["from"]="invoice";
     $this->load->view("invoices",$data_invoice);
     $this->session->set_userdata(array("idcomfirm"=>""));     						  					  		
      					
      						  	}else 
      						  	{
      						  		//header('Location:index.php?liste/listtour');
      						  		echo "<h2>fait deux fois action invoice , l'erreur 101</h2><a href='index.php?liste/listtour'>back to menu</a>";
      						  	}
      						  	
      				 	
      				 	
      				 	break;		  	
      						  	
				
      				 	
      case "invoicegroup":
      				 			$idcomfirm=$this->input->get_post("idcomfirm");
      				 			$idinscr=$this->input->get_post("idinscr");
      						  	$iduser=$this->input->get_post("iduser");
      						  	$addionalprixcommentaire=$this->input->get_post("addionalprixcommentaire");
      						  	$prixadditonal=$this->input->get_post("prixadditonal");
      						  	$typepaiement=$this->input->get_post("typepaid");
      						  	$balance=$this->input->get_post("balance");
      						  	$idclients=$this->input->get_post("idcleint");
      						  
      						  	if($idinscr!=""&&$iduser!=""&&$idcomfirm==$this->session->userdata("idcomfirm"))
      						  	{
      						  		$data=array("addionalprixcommentaire"=>$addionalprixcommentaire,"prixadditonal"=>$prixadditonal,"typepaiement"=>$typepaiement,"balance"=>$balance);
      						  		$idinsert=$this->centermod-> insertetemplate("invoice",$data);
      						  //add relatif enter inscription and invoice
      						  		$arr_idinscr=explode(",", $idinscr);
      						  		
      						  		foreach($arr_idinscr as $idinscr){
      						  		$data2=array("insrc_idinscriptions"=>$idinscr,"inv_idinvoice"=>$idinsert,"users_idusers"=>$iduser);
      						  		$idinsert_relatif=$this->centermod-> insertetemplate("relatif_invoice",$data2);
      						  		$infoallforinvoice[]=$this->centermod->allinfoforinvoice($idinscr);
      						  	}
      						  		
      						  		$linfoper=$this->centermod->seachclientbyid($idclients);
      					  		/* convertir le chambrel type*/
      						  		$chambreinfo="";
      						  		foreach ($infoallforinvoice as $infoinvoice)
      						  		{
      						  		 switch($infoinvoice[0]['chambre']){
										case '1':
											$chambreinfo= $chambreinfo.'Single X '.$infoinvoice[0]['chambreqty'];
										break;
										case '2':
											$chambreinfo=$chambreinfo. 'Double X '.$infoinvoice[0]['chambreqty'];
										break;
										case '3':
											$chambreinfo=$chambreinfo.'Triple X '.$infoinvoice[0]['chambreqty'];
										break;
												case '4':
											$chambreinfo=$chambreinfo. 'Quadruple X '.$infoinvoice[0]['chambreqty'];
										break;
											}
      						  		}
											

								switch($infoallforinvoice[0][0]['paid'])
									{
								case '1':
									$paid= 'Yes';
									break;
								case '0':
									$paid='No';
									break;
									} 			
						  		/*___________________________*/
      						  		$page="code:".$infoallforinvoice[0][0]['tourname']."-".$infoallforinvoice[0][0]["tourcode"].";Date:".$infoallforinvoice[0][0]["tourdate"].";lastname:".$infoallforinvoice[0][0]['lastname'].";firstname:".$infoallforinvoice[0][0]['firstname']
      						  		.";telphone:".$linfoper[0]['telphone'].";email:".$linfoper[0]['email'].",address".$linfoper[0]['address'].";people:1"."chambre:".$chambreinfo.";salesprice:".$infoallforinvoice[0][0]['salesprice'].";balance:".$infoallforinvoice[0][0]['balance'].";Paid:".$paid.";typepaiement:".$infoallforinvoice[0][0]['typepaiement'].
      						  		";agency:". $infoallforinvoice[0][0]['agency'].";agent: ". $infoallforinvoice[0][0]['agent'].";language:".$infoallforinvoice[0][0]['language'].
      						  		";description:".$infoallforinvoice[0][0]['description'];
      								$pagedata=array('page'=>$page);
     								$updatepage=$this->centermod->updatetemplate("invoice",$pagedata,"idinvoice=$idinsert");
     								$data_invoice["idinvoice"]=$idinsert;	
	 								$data_invoice["infoper"]=$linfoper;
     								$data_invoice["allinfo"]=$infoallforinvoice;
    								$this->load->view("invoicesgroup",$data_invoice);
     								$this->session->set_userdata(array("idcomfirm"=>""));     						  					  		
      					
      						  	}else 
      						  	{
      						  		//header('Location:index.php?liste/listtour');
      						  		//print_r($idinscr."---"."$iduser");
      						  		echo "<h2>fait deux fois action invoice group , l'erreur 101</h2><a href='index.php?liste/listtour'>back to menu</a>";
      						  	}
      						  	
      				 	
      				 	
      				 	break;		  	
      						  					 	
      				 	
      						  	}//swich
				
				
							
			}						
		
			
			}//function action add
			
			
		
//load page

		function addnewuser()
			{
					
				if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
					{
					header('Location:index.php?pages/loginadmin');
						
					}else {
					$data=array("type"=>"add");
					$this->load->view("edituserform",$data);
					}
			}
			
		
		function actionaddnewuser()
			{
					
				if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
				{
					header('Location:index.php?pages/loginadmin');
						
				}else
			 	{
					$name=$this->input->get_post("name"); 
			 		$pwd=$this->input->get_post("pwd"); 
					$email=$this->input->get_post("email"); 
					$level=$this->input->get_post("level"); 
					$totalfind=$this->centermod->verifier($name,$pwd,$email);
					if($totalfind==0)
					{
					$data=array("pwd"=>$pwd,"email"=>$email,"level"=>$level,"name"=>$name,"fk_idagency"=>1);
					$idinsert=$this->centermod-> insertetemplate("users",$data);
					redirect('index.php?liste/listuser', 'refresh');
					}
					else {echo "user exit , return to add new <br/> <a href='index.php?add/addnewuser'>return to add page</a>";}
					}
			
			}
			
/****************** party for partner module   ************************/

		function addnewpartner()
			{
					
				if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
					{
					header('Location:index.php?pages/loginadmin');
						
					}else {
					$data=array("type"=>"add");
					$this->load->view("partners/editpartnerform",$data);
					}
			}
			
		
		function actionaddnewpartner()
			{
					
				if($this->session->userdata("user")==false ||$this->session->userdata("level")!="admin")
				{
					header('Location:index.php?pages/loginadmin');
						
				}else
			 	{
					$name=$this->input->get_post("name"); 
					$pwd=$this->input->get_post("pwd"); 
					$address=$this->input->get_post("address"); 
					$tel=$this->input->get_post("tel"); 
					$fax=$this->input->get_post("fax"); 
					$email=$this->input->get_post("email"); 
					$active=$this->input->get_post("active"); 
					$sptype=$this->input->get_post("sptype");
			 		$totalfind=$this->centermod->verifierpartner($name,$pwd,$email);
					if($totalfind==0)
					{
					$data=array("name"=>$name,"pwd"=>$pwd,"address"=>$address,"tel"=>$tel,"fax"=>$fax,"active"=>$active,"email"=>$email,"sptype"=>$sptype);
					$idinsert=$this->centermod-> insertetemplate("partners",$data);
					redirect('index.php?liste/listpartners', 'refresh');
					}
					else {echo "user exit , return to add new <br/> <a href='index.php?add/addnewpartner'>return to add page</a>";}
					}
			
			}			
			
/*********************************************************************/				
			
}//class
